﻿@model SMECustomerWebsite.Models.ViewModels.CustomerManager.CustSubSegmentViewModel

@Html.Action("SubMenuCustomer", "System")
<!-- start accordion -->
<div class="accordion cm-accordion" id="accordion" role="tablist" aria-multiselectable="true">
    @Html.Action("CustInfo", "System")
    <div class="panel">
        <div class="panel-heading collapsed">
            <a role="tab" id="headingOne-msme-cust" data-toggle="collapse" data-parent="#accordion" href="#collapseOne-msme-cust" aria-expanded="false" aria-controls="collapseOne-msme-cust">
                <h4 class="panel-title cm_cp_gr_general_lbl">@SMECustomerWebsite.Core.Resources.Resource.SubMsme.ToUpper()</h4>
            </a>
            <span id="total-msme-cust-lbl" class="panel-title cm_cp_gr_lbl_total">@SMECustomerWebsite.Core.Resources.Resource.TotalLbl (@Model.CountMsme)</span>
        </div>
        @Html.Action("CustSubSegmentMSMETemp", "System")
    </div>
    <div class="panel">
        <div class="panel-heading collapsed">
            <a role="tab" id="headingOne-sme-cust" data-toggle="collapse" data-parent="#accordion" href="#collapseOne-sme-cust" aria-expanded="false" aria-controls="collapseOne-sme-cust">
                <h4 class="panel-title cm_cp_gr_general_lbl">@SMECustomerWebsite.Core.Resources.Resource.SubSme.ToUpper()</h4>
            </a>
            <span id="total-sme-cust-lbl" class="panel-title cm_cp_gr_lbl_total">@SMECustomerWebsite.Core.Resources.Resource.TotalLbl (@Model.CountSme)</span>
        </div>
        @Html.Action("CustSubSegmentSMETemp", "System")
    </div>
    <div class="panel">
        <div class="panel-heading collapsed">
            <a role="tab" id="headingOne-mme-cust" data-toggle="collapse" data-parent="#accordion" href="#collapseOne-mme-cust" aria-expanded="false" aria-controls="collapseOne-mme-cust">
                <h4 class="panel-title cm_cp_gr_general_lbl">@SMECustomerWebsite.Core.Resources.Resource.SubMme.ToUpper()</h4>
            </a>
            <span id="total-mme-cust-lbl" class="panel-title cm_cp_gr_lbl_total">@SMECustomerWebsite.Core.Resources.Resource.TotalLbl (@Model.CountMme)</span>
        </div>
        @Html.Action("CustSubSegmentMMETemp", "System")
    </div>
</div>
<!-- end of accordion -->
@section scripts
{
    <script type="text/javascript">
        $(document).ready(function () {
            $('#total-msme-cust-lbl').click(function () {
                $('#collapseOne-msme').collapse('show');
            });
            $('#total-mme-cust-lbl').click(function () {
                $('#collapseOne-mme').collapse('show');
            });
            $('#total-sme-cust-lbl').click(function () {
                $('#collapseOne-sme').collapse('show');
            });
        });
    </script>

    <script src="~/Scripts/custom_search_table.js"></script>
    <!-- bootstrap-daterangepicker -->
    <script src="~/scripts/datepicker/moment/moment.min.js"></script>
    <script src="~/scripts/datepicker/datepicker/daterangepicker.js"></script>
    <script src="/scripts/tableeditable/dataTables.rowsGroup.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var lcColumn = [
                                    { "sName": "CIF", "bSortable": false },
                                { "sName": "NAME", "bSortable": false },
                                { "sName": "VPB INDUSTRY", "bSortable": false },
                                { "sName": "DATE OPEN CIF", "bSortable": false },
                                { "sName": "INFO", "bSortable": false }]
            var lcLenCol = 4;
            var lcCifCol = 0;
            var dataSearchLoanMatdt = [{ id: 5, text: 'MSBO' }, { id: 0, text: 'CIF' }, { id: 1, text: 'Name' }, { id: 2, text: 'VPB Insdustry' }];
            switch (@Model.CurrentUser.GroupIdentifier) {
                case 1:
                    lcColumn = [
                            { "sName": "REGION", "bSortable": false },
                            { "sName": "BRANCH", "bSortable": false },
                            { "sName": "DAO", "bSortable": false },
                            { "sName": "MSBO", "bSortable": false },
                            { "sName": "CIF", "bSortable": false },
                            { "sName": "NAME", "bSortable": false },
                            { "sName": "VPB INDUSTRY", "bSortable": false },
                            { "sName": "DATE OPEN CIF", "bSortable": false },
                            { "sName": "INFO", "bSortable": false }];
                    lcLenCol = 8;
                    lcCifCol = 4;
                    dataSearchLoanMatdt = [{ id: 3, text: 'Region' }, { id: 4, text: 'Branch' }, { id: 5, text: 'MSBO' }, { id: 0, text: 'CIF' }, { id: 1, text: 'Name' }, { id: 2, text: 'VPB Insdustry' }];
                    break;
                case 2:
                    lcColumn = [
                            { "sName": "BRANCH", "bSortable": false },
                            { "sName": "DAO", "bSortable": false },
                            { "sName": "MSBO", "bSortable": false },
                            { "sName": "CIF", "bSortable": false },
                            { "sName": "NAME", "bSortable": false },
                            { "sName": "VPB INDUSTRY", "bSortable": false },
                            { "sName": "DATE OPEN CIF", "bSortable": false },
                            { "sName": "INFO", "bSortable": false }];
                    lcLenCol = 7;
                    lcCifCol = 3;
                    dataSearchLoanMatdt = [{ id: 4, text: 'Branch' }, { id: 5, text: 'MSBO' }, { id: 0, text: 'CIF' }, { id: 1, text: 'Name' }, { id: 2, text: 'VPB Insdustry' }];
                    break;
                case 3:
                    lcColumn = [
                            { "sName": "DAO", "bSortable": false },
                            { "sName": "MSBO", "bSortable": false },
                            { "sName": "CIF", "bSortable": false },
                            { "sName": "NAME", "bSortable": false },
                            { "sName": "VPB INDUSTRY", "bSortable": false },
                            { "sName": "DATE OPEN CIF", "bSortable": false },
                            { "sName": "INFO", "bSortable": false }];
                    lcLenCol = 6;
                    lcCifCol = 2;
                    dataSearchLoanMatdt = [{ id: 5, text: 'MSBO' }, { id: 0, text: 'CIF' }, { id: 1, text: 'Name' }, { id: 2, text: 'VPB Insdustry' }];
                    break;
                default:
                    break;
            }
            var optionDatatable = {
                "order": [[0, 'asc']],
                "bServerSide": true,
                "bProcessing": true,
                "responsive": true,
                "bAutoWidth": false,
                "aLengthMenu": [10, 30, 50, 100],
                "pageLength": 10,
                rowsGroup: [0, 1, 2,3],
                "sAjaxSource": '@Url.Action("CustSubSegmentData", "CustomerManager")' + '?type=msme',
                "fnServerData": function (sSource, aoData, fnCallback) {
                    $.ajax({
                        "dataType": 'json',
                        "type": "POST",
                        "url": sSource,
                        "data": aoData,
                        "success": fnCallback
                    });
                },
                "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'dataTables_wrapper'ip>>",
                "sPaginationType": "simple_numbers",//"full_numbers",
                "aoColumns": lcColumn,
                "aoColumnDefs": [{
                    "aTargets": [lcLenCol],
                    "mRender": function (data, type, full) {
                        return '<a class=\"btn btn-primary btn-xs\" onclick=\"showCustomerInfo(\'' + full[lcCifCol] + '\');\"><i class="fa fa-info"></i></a>';
                    }
                }],
                initComplete: function () {
                    this.api().columns().every(function () {
                        var column = this;
                        switch (column.context[0].aoHeader[0][column.index()].cell.innerText) {
                            case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.Zone.ToUpper())':
                                createFilterRegion(column, '@SMECustomerWebsite.Core.Resources.Resource.Zone');
                                break;
                            case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.DateOpenCifHeader)':
                                createFilterDate(column);
                                break;
                            case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.Branch.ToUpper())':
                                createFilterBranch(column);
                                break;
                            case '@Html.Raw(SMECustomerWebsite.Core.Resources.Resource.MSBONameHeader.ToUpper())':
                                createFilterMSBOName(column, 1);
                                break;
                            case 'DAO':
                                createFilterMSBOName(column, 2);
                                break;
                            default:
                                if (column.index() < lcLenCol) {
                                    var select = $('<input type="text" class="filtet-table">')
                                                            .appendTo($(column.header()))
                                                            .on('keyup change', function () {
                                                                column.search(this.value).draw();
                                                            });
                                }
                                break;

                        }
                    });
                },
                "drawCallback": function (settings) {
                    $('table.custom_table th').removeClass().addClass('column-title');
                }
            };
            var table_msme = $('#cm-customer-portfolio-msme').DataTable(optionDatatable);
            $(".search_column_msme").select2({
                placeholder: "Select column",
                data: dataSearchLoanMatdt
            });

            optionDatatable.sAjaxSource=  '@Url.Action("CustSubSegmentData", "CustomerManager")' + '?type=mme'
            var table_mme = $('#cm-customer-portfolio-mme').DataTable(optionDatatable);

            optionDatatable.sAjaxSource = '@Url.Action("CustSubSegmentData", "CustomerManager")' + '?type=sme';
            var table_sme = $('#cm-customer-portfolio-sme').DataTable(optionDatatable);
        })
    </script>
}